$(function () {
    var layer = layui.layer;
    var form = layui.form;
    var laypage = layui.laypage;
    //----------------------------------------------------------------
    // 页面查询参数
    var query = {
        pagenum: 1, //页码值
        pagesize: 5, //每页显示几条数据
        username: '', //姓名
        sno: '', //学号
    }
    //----------------------------------------------------------------
    //渲染分页功能
    function renderPage(total) {
        // console.log(total);
        laypage.render({
            elem: 'pageBox', //分页容器的id
            count: total, //数据总数，从服务端得到
            limit: query.pagesize, //每页显示几条数据
            curr: query.pagenum,
            layout: ["count", "limit", "prev", "page", "next", "skip"],
            limits: [5, 10, 15, 20],
            jump: function (obj, first) {
                // console.log(first);
                query.pagenum = obj.curr;
                query.pagesize = obj.limit;
                // 首行不执行
                if (!first) {
                    initUsersList()
                }
            },

        });
    }
    //----------------------------------------------------------------
    initUsersList();
     //----------------------------------------------------------------
    //获取所有用户信息列表
    function initUsersList() {
        var username =window.parent.$('#name').val()
        var sno = window.parent.$('#sno').val()
        console.log(username);
        console.log(sno);
        query.username = username;
        query.sno = sno;
        $.ajax({
            method: 'POST',
            url: '/my/userinfo/users/',
            data: query,
            success: function (res) {
                var htmStr = template('tpl-table', res);
                $('tbody').html(htmStr)
                // renderPage(res.total)
            }
        })
    }

      //为查看评分按钮绑点击事件
  var id =null;
  var viewScor_index = null;
$('tbody').on('click', '.btn_view', function () {
    viewScor_index = layer.open({
        type: 1,
        area: ['900px', ''],
        title: '伊犁银保监分局部门负责人平时考核量化考评表',
        content: $('#dialog_viewlog').html(),
        success: function () {
            form.render();
        }
    })
    id = $(this).attr('data_id')
    $.ajax({
        method: 'GET',
        url: '/my/userinfo/user/' + id,
        success: function (res) {
            var data = res.data;
            console.log(data);
            var table = $('table.layui-table');
            table.find('tbody tr').each(function (index, row) {
                $(row).find('td').each(function (cellIndex, cell) {
                    if ($(cell).find('input').length > 0) {
                        var inputName = $(cell).find('input').prop('name');
                        if (data[inputName]) {
                            $(cell).find('input').val(data[inputName]);
                        }
                    }
                });
            });
        }
    })
});
$('body').on('click', '#form_viewUser button[type="button"]', function (e) {
    e.preventDefault();
    layer.close(viewScor_index);
});
})